function bkgnd=avibackground( src, factor )
% bkgnd=avibackground( src, factor ) - cretaes movie with bavkground extracted from
% source movie. result has same number of frames
% AUTOSTOP

% frames num
srcframes = size( src, 2 );

% first background
bkgnd = src( 1 );
background = double( src( 1 ).cdata );

% iterate
for i = 2:(srcframes)
	% progress indicator
	disp( sprintf( '%d/%d', i-1, srcframes -1 ) );

	% get src frame
	srcframe = double( src( i ).cdata );
	
	% calculate new backgorund frame
	background = background * (1 - factor) + srcframe * factor;
	
	% prepare frame
	frame.cdata = uint8( background );
	frame.colormap = src( i ).colormap;

	% append to result
	bkgnd = [ bkgnd frame ];
end

	
	